﻿// -------------------------------------------------------------------------
//    @FileName         :    NFMasterModule.cpp
//    @Author           :    Gao.Yi
//    @Date             :    2025-09-09
//    @Email			:    445267987@qq.com
//    @Module           :    NFMasterModule
//    @Desc             :
//
// -------------------------------------------------------------------------

#include "NFMasterModule.h"

#include "NFPacketSendUtil.h"
#include "NFPlayer.h"
#include "NFServiceSns.h"
#include "NFSession.h"
#include "NFSkyArenaPart.h"
#include "NFSkyArenaService.h"
#include "proto_cs_cmd.nanopb.h"
#include "proto_cs_master.pb.h"

NFMasterModule::NFMasterModule(NFIPluginManager* p):NFLogicDynamicModule(p)
{
}

NFMasterModule::~NFMasterModule()
{
}

int NFMasterModule::Awake()
{
    RegisterClientMessage(NF_ST_LOGIC_SERVER, E_CS_MASTER_GET_APPLY_LIST_REQ);
    return 0;
}

int NFMasterModule::OnHandleClientMessage(NFDataPackage& packet, NFSession* pSession, const proto_ff::Proto_CSReq& req)
{
    CHECK_NULL(0, pSession);
    if (!m_pObjPluginManager->IsInited(NF_ST_LOGIC_SERVER))
    {
        NFLogError(NF_LOG_DEFAULT, packet.nParam1, "Logic Server not inited, drop client msg:{}", packet.ToString());
        return -1;
    }

    if (m_pObjPluginManager->IsServerStopping())
    {
        NFLogError(NF_LOG_DEFAULT, packet.nParam1, "Logic Server is Stopping, drop client msg:{}", packet.ToString());
        return ERR_CODE_SERVER_IS_STOPPING;
    }

    int iRetCode = 0;
    switch (packet.nMsgId)
    {
        case E_CS_MASTER_GET_APPLY_LIST_REQ:
        {
            iRetCode = OnHandleGetApplyListReq(packet, pSession, req);
            break;
        }
        default: NFLogError(NF_LOG_DEFAULT, 0, "not handle msg:{}", packet.nMsgId);
    }

    return iRetCode;
}

int NFMasterModule::OnHandleServerMessage(uint32_t msgId, NFDataPackage& packet, uint64_t param1, uint64_t param2)
{
    return 0;
}

int NFMasterModule::OnHandleGetApplyListReq(NFDataPackage& packet, NFSession* pSession, const proto_ff::Proto_CSReq& req)
{
    CHECK_NULL(0, pSession);

    NFPlayer* pPlayer = pSession->GetPlayer();
    CHECK_NULL(0, pPlayer);

    const proto_ff::Proto_CSMasterGetApplyListReq& csReq = req.master_get_apply_req();

    proto_ff::Proto_CSRsp rsp;
    proto_ff::Proto_SCMasterGetApplyListRsp* pRsp = rsp.mutable_master_get_apply_rsp();
    if (csReq.is_open())
    {
        pRsp->set_is_dirty(false);
    }
    else
    {
        pRsp->set_is_dirty(false);
    }
    return NFPacketSendUtil::SendToClient( pPlayer, E_SC_MASTER_GET_APPLY_LIST_RSP, &rsp);
}
